﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using System.Globalization;

namespace PoCDie2
{
  public partial class Form1 : Form
  {

    public Form1() {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e) {
      OpenFileDialog ofd = new OpenFileDialog();

      ofd.Filter = "Excel Worksheets|*.xls*|All Files|*.*";
      ofd.InitialDirectory = "C:\\";

      DialogResult userOk = ofd.ShowDialog();

      if (userOk == DialogResult.OK) {
        //lblText.Text = ofd.FileName;
        CultureInfo oldCI;
        oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
        System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
        Stream fileStream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);

        Excel.Application xlApp;
        Excel.Workbook xlWorkBook;
        Excel.Worksheet xlWorkSheet;
        Excel.Range range;

        xlApp = new Excel.ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Open(ofd.FileName.ToString(), 0, true, 51, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

        range = xlWorkSheet.UsedRange;

        lblText.Text = range.Cells[1, 1].ToString();
        System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
      }
    }

  }
}
